package com.kkb.controller;

import com.kkb.vo.Team;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("param")
public class ParamController {
    @RequestMapping("index")
    public ModelAndView index(){
        System.out.println("index");
        return new ModelAndView("param");
    }
    @RequestMapping("test01")
    public ModelAndView test01(Integer id,String name,String location){
        System.out.println(id);
        System.out.println(name);
        System.out.println(location);
        return new ModelAndView("ok");
    }
    @RequestMapping("test02")
    public ModelAndView test02(@RequestParam("id") Integer teamId,@RequestParam("name") String teamName,
                               @RequestParam("location") String location){
        System.out.println(teamId);
        System.out.println(teamName);
        System.out.println(location);
        return new ModelAndView("ok");
    }
    @RequestMapping("test03")
    public ModelAndView test03(Team team){
        System.out.println(team);
        return new ModelAndView("ok");
    }
    @RequestMapping("test04")
    public ModelAndView test04(HttpServletRequest request){
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String location = request.getParameter("location");
        int id1 = 0;
        if(id!=null){
            id1 = Integer.valueOf(id);
        }
        System.out.println(id);
        System.out.println(name);
        System.out.println(location);
        return new ModelAndView("ok");
    }
//http://localhost:8080/param/test05/1001/liu/ying
    @RequestMapping("test05/{id}/{name}/{location}")
    public ModelAndView test05(@PathVariable("id") Integer id,
                               @PathVariable("name") String name,
                               @PathVariable("location") String location){
        System.out.println(id);
        System.out.println(name);
        System.out.println(location);
        return new ModelAndView("ok");
    }
    @RequestMapping("test06")
    public ModelAndView test06(Team team){
        System.out.println(team);
        return new ModelAndView("ok");
    }
    @RequestMapping("test07")
    public ModelAndView test07(String[] name,HttpServletRequest request){
        for(String str:name){
            System.out.println(str);
        }
        System.out.println();
        System.out.println();
        System.out.println();
        String[] names = request.getParameterValues("name");
        for (String str2:names){
            System.out.println(str2);
        }
        return new ModelAndView("ok");
    }

    @RequestMapping("test08")
    public ModelAndView test08(@RequestParam("name") List<String> name){
        for(String str : name){
            System.out.println(str);
        }
        return new ModelAndView("ok");
    }
}
